package org.example.oa.activity.controller;


import org.example.framework.dto.PageDTO;
import org.example.framework.dto.ResponseDTO;
import org.example.oa.activity.able.ActivityAble;
import org.example.oa.activity.entity.ActivityApply;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * curl 测试方法
 * curl -X POST -H "Content-Type:application/json;charset=utf-8"  http://localhost:8080/activity-apply/search -d {}
 * </p>
 *
 * @author tangxiao
 * @since 2021-10-11
 */
@Controller
@RequestMapping("/activity-apply/")
public class ActivityApplyController {


    @Autowired
    private ActivityAble activityAble;

    @RequestMapping(value = "search", method = RequestMethod.POST)
    @ResponseBody
    public ResponseDTO<PageDTO<List<ActivityApply>>> search(@RequestBody PageDTO<ActivityApply> dto) {
        return ResponseDTO.ok(activityAble.doSearch(dto));
    }

    @RequestMapping(value = "details", method = RequestMethod.POST)
    @ResponseBody
    public ResponseDTO<ActivityApply> details(@RequestBody ActivityApply dto) {
        return ResponseDTO.ok(activityAble.doGet(dto));
    }

    @RequestMapping(value = "save", method = RequestMethod.POST)
    @ResponseBody
    public ResponseDTO<Boolean> save(@Validated @RequestBody ActivityApply dto) {
        return ResponseDTO.ok(activityAble.doSave(dto));
    }

    @RequestMapping(value = "update", method = RequestMethod.POST)
    @ResponseBody
    public ResponseDTO<Boolean> update(@Validated @RequestBody ActivityApply dto) {
//        return ResponseDTO.ok(activityAble. (dto))
        return null;
    }


    @RequestMapping(value = "delete", method = RequestMethod.POST)
    @ResponseBody
    public ResponseDTO<Boolean> delete(@RequestBody @Validated @NonNull Serializable id) {
        return ResponseDTO.ok(activityAble.doRemoveById(id));
    }
}
